<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class WlGoodsResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            "id"=>$this->id,
            "name"=>$this->goods_name,
            "img"=>get_img_url($this->goods_image),
            "goodsCategory"=>new GoodsCategoryResource($this->whenLoaded("goodsCategory")),
            "goodsContent" =>$this->content,
            "location_id"=>$this->location_id,
            "spec"=>$this->spec,
            "tags"=>$this->tags?explode(",",$this->tags):"",
            "price"=>$this->price==0?"咨询客户经理":$this->price,
            "author"=>new AuthorResource($this->whenLoaded("author")),
        ];
    }
}
